//
//  UIButton+Add.swift
//  QuantumWar
//
//  Created by mysj on 16/7/21.
//  Copyright © 2016年 zeng. All rights reserved.
//

import UIKit

extension UIButton {

    
    convenience init(title: String = "", color: UIColor = UIColor(),imgName: String, backImgName: String = "") {
        self.init()
        setImage(UIImage(named: imgName), forState: .Normal)
        setImage(UIImage(named: imgName + "h"), forState: .Highlighted)
        
        if backImgName != "" {
            setBackgroundImage(UIImage(named: backImgName), forState: .Normal)
            setBackgroundImage(UIImage(named: backImgName + ""), forState: .Highlighted)
        }
        
        if title != "" {
            setTitle(title, forState: .Normal)
            setTitleColor(color, forState: .Normal)
        }
        // 会根据背景图片的大小调整尺寸
        sizeToFit()
    }
    
    
    convenience init(title: String, color: UIColor, imageName: String = "") {
        self.init()
        
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        
        if imageName != "" {
            setBackgroundImage(UIImage(named: imageName), forState: .Normal)
        }
    }

}
